﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestDxfDocument
{
    class Round_plate_teeth
    {
        public static void _ThreadCuttingDieRoundShape(Dictionary<string, Object> data)  //圆板牙
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层

            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            /*
            double d = 8;
            double p = 1.25;
            double b = 5;
            double D = 25;
            double DD1= D - (b/2+(6*System.Math.Sqrt(2)*Math.Tan (6*pi /180)));
            double D1 = 22.5;
            double E = 9;
            double E1 = 1 ;
            
            double c = 0.8;
            double a = 0.5;
            Vector2 pzk = new Vector2(0, 0);
            Vector2 pzk1 = fun.Polar(pzk,pi/2,(d/2)-p);
            double d1 = 0.1+(D1 /2)-(d/2-p );//排泄孔
            double ajj = 20;
            double dj =1;
            double l = 3;
            double drjj =1;
            double sh = 0;
            */
            
            double d = Convert.ToDouble(data["d"]);
            double p = Convert.ToDouble(data["p"]);
            double b = Convert.ToDouble(data["b"]);
            double D = Convert.ToDouble(data["bd"]);
            double DD1 = D - (b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)));
            double D1 = Convert.ToDouble(data["d1"]);
            double E = Convert.ToDouble(data["oal"]);
            // double E1 = E * 3/5;
            double E1 = Convert.ToDouble(data["e1"]);
            double c = Convert.ToDouble(data["c"]);
            double a = Convert.ToDouble(data["a"]);
            double ajj = Convert.ToDouble(data["ajj"]);
            double dj = Convert.ToDouble(data["dj"]);
            double l = Convert.ToDouble(data["l"]);
            double drjj = Convert.ToDouble(data["drjj"]);
            double sh = Convert.ToDouble(data["sh"]);
            double d1 = 0.1 + (D1 / 2) - (d / 2 - p);//排泄孔
            
            /*
            double d = 1;
            double p = 0.25;
            double D = 16;
            double D1 = 11;
            double E = 5;
            double E1 = 2;
            double c = 0.5;
            double b = 3;
            double a = 0.2;
     
            double d1 = 0.01+(D1 /2)-(d/2-p );
            double DD1 = D - (b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180)));
              */
            double yx = (d / 2 - p);
            double yx2 = d / 2;
            double zxj = (D1 / 2) - (d1 / 2);
            double jd1 = (d1 / 2);
            double kc = 85 * pi / 180;
          

            //double E1 = (8 / 9 * E);

            if (D > 16)
            {
                D1 = D - ((b / 2 + (6 * System.Math.Sqrt(2) * Math.Tan(6 * pi / 180))) * 2);
            }

            //double E1 = (8 / 9 * E);


            if (D < 25)
            {

                if (E1 == 0)
                {
                    E1 = 3 / 5.0*E ;
                }


                //中心三角带
                Vector2 p0 = new Vector2(0, 0);
                Vector2 p1 = new Vector2(0, D1 / 2);
                Vector2 p2 = fun.Polar(p0, 210 * pi / 180, D1 / 2);
                Vector2 p2y = fun.Polar(p0, 210 * pi / 180, D1 / 2 - d1 / 2); //-135度排泄孔圆心

                Vector2 p3 = fun.Polar(p0, -30 * pi / 180, D / 2 - a);
                Vector2 p3y = fun.Polar(p0, -30 * pi / 180, D1 / 2 - d1 / 2);// -45度排泄孔圆心

                //中心螺纹孔/排泄孔
                Vector2 p4 = fun.Polar(p0, pi / 2, D1 / 2);
                Vector2 p1y = fun.Polar(p4, pi / -2, d1 / 2);//90度排泄孔圆心
                Vector2 p5 = fun.Polar(p0, pi * 0.5 + Math.Acos((yx * yx + zxj * zxj - jd1 * jd1) / (2 * yx * zxj)), yx);

                Vector2 p6 = fun.Polar(p0, pi / 2 + Math.Acos((yx2 * yx2 + zxj * zxj - jd1 * jd1) / (2 * yx2 * zxj)), yx2);
                Vector2 p7 = fun.mirrorpoint(p5, p0, p4);
                Vector2 p8 = fun.mirrorpoint(p6, p0, p4);

                var p9 = fun.PointRotate(p0, p5, 120 * pi / 180);
                var p10 = fun.PointRotate(p0, p5, 240 * pi / 180);
                var p11 = fun.PointRotate(p0, p6, 120 * pi / 180);
                var p12 = fun.PointRotate(p0, p6, 240 * pi / 180);
                var p13 = fun.PointRotate(p0, p7, 120 * pi / 180);
                var p14 = fun.PointRotate(p0, p7, 240 * pi / 180);
                var p15 = fun.PointRotate(p0, p8, 120 * pi / 180);
                var p16 = fun.PointRotate(p0, p8, 240 * pi / 180);
                //头顶卡槽
                Vector2 p17 = fun.Polar(p0, kc, D / 2);
                Vector2 p18 = fun.Polar(p0, pi / 2, D);
                Vector2 p19 = fun.mirrorpoint(p17, p0, p18);
                Vector2 p20 = fun.Polar(p17, kc - pi, D / 2 - D1 / 2);
                Vector2 p21 = fun.mirrorpoint(p20, p0, p18);

                //中心线
                Vector2 zxx1 = fun.Polar(p18, pi / -2, D * 2);
                Vector2 zxx2 = fun.Polar(p0, pi, D);
                Vector2 zxx3 = fun.Polar(zxx2, 0, D * 2);



                //两个耳朵

                Vector2 p22 = fun.Polar(p0, 135 * pi / 180, D1 / 2);
                Vector2 p23 = fun.Polar(p22, pi / -2, System.Math.Sqrt(2) * c);
                Vector2 p24 = fun.Polar(p0, (45 - 16) * pi / 180 + pi / 2, D / 2);
                Vector2 p25 = fun.Polar(p0, 157 * pi / 180, D / 2);
                Vector2 p26 = fun.mirrorpoint(p23, p0, p18);
                Vector2 p27 = fun.mirrorpoint(p24, p0, p18);
                Vector2 p28 = fun.mirrorpoint(p25, p0, p18);


                //下面那个槽
                Vector2 p29 = fun.Polar(p0, 11 * pi / 180 - pi / 2, D / 2);
                Vector2 p30 = fun.Polar(p29, 135 * pi / 180, System.Math.Sqrt(Math.Pow(b, 2) / 2));
                Vector2 p31 = fun.mirrorpoint(p29, p0, p18);






                //刨视图
                Vector2 p32 = fun.Polar(p0, pi / -2, D / 2);
                Vector2 p33 = fun.Polar(p32, 0, D * 1.5);
                Vector2 p333 = fun.Polar(p33, pi / 2, a);
                //刨视图中心线
                Vector2 ppzy = new Vector2(p33.X + E / 2, p33.Y - E / 2);
                Vector2 ppzy1 = fun.Polar(ppzy, pi / 2, D + E);
                Vector2 p34 = fun.Polar(p33, pi / 2, D / 2 - a - D1 / 2);
                Vector2 p35 = new Vector2(p34.X, p34.Y + D1 / 4);
                Vector2 p36 = fun.Polar(p35, pi / 2, p);
                Vector2 p3z = fun.Polar(p35, pi / 2, D1 / 4);//中心线
                Vector2 pzxx = fun.Polar(p3z, pi, E / 2);
                Vector2 pzxx1 = fun.Polar(pzxx, 0, E * 2);
                Vector2 p37 = fun.Polar(p3z, pi / 2, D1 / 4);
                Vector2 p38 = fun.Polar(p37, pi / 2, p);
                Vector2 p39 = fun.Polar(p37, pi / 2, D1 / 4);
                Vector2 p42 = new Vector2(p33.X, D / 2);
                Vector2 p43p = fun.mirrorpoint(p42, ppzy, ppzy1);
                Vector2 p43 = fun.Polar(p43p, pi, a);
                Vector2 p444 = new Vector2(p43.X + a, p43.Y - a);
                Vector2 p44 = fun.mirrorpoint(p39, ppzy, ppzy1);
                Vector2 p45 = fun.mirrorpoint(p34, ppzy, ppzy1);
                Vector2 p334 = fun.mirrorpoint(p333, ppzy, ppzy1);
                Vector2 p46 = new Vector2(p334.X - a, p334.Y - a);
                Vector2 p47 = fun.Polar(p33, 0, a);



                /*
                Vector2 p43 = fun.Polar(p42,0,E-a);
                Vector2 p444 = new Vector2(p43.X + a, p43.Y - a);
                
                Vector2 p44  = fun.mirrorpoint(p39, ppzy, ppzy1);
                Vector2 p45 = fun.Polar(p44,pi/-2,D1 );
                Vector2 p334=fun.mirrorpoint(p34, ppzy, ppzy1);
                Vector2 p46 = new Vector2(p334.X -a,p334.Y -a);
                Vector2 p47 = new Vector2(p33.X +a,p33.Y );

                */



                //右边深度
                Vector2 p48 = fun.Polar(p39, 0, E1);
                Vector2 p49 = fun.Polar(p38, 0, E1);
                Vector2 p50 = fun.Polar(p37, 0, E1);
                Vector2 p51 = fun.Polar(p36, 0, E1);
                Vector2 p52 = fun.Polar(p35, 0, E1);
                Vector2 p53 = fun.Polar(p34, 0, E1);


                //中间的间隔
                Vector2 p54 = fun.Polar(p35, 45 * pi / 180, (System.Math.Sqrt(2)) * (E1 / 3));
                Vector2 p55 = fun.Polar(p54, 0, E1 / 3);
                Vector2 p56 = fun.Polar(p54, pi / 2, p);
                Vector2 p57 = fun.Polar(p56, 0, E1 / 3);
                Vector2 p58 = fun.Polar(p37, -45 * pi / 180, (System.Math.Sqrt(2)) * (E1 / 3));
                Vector2 p59 = fun.Polar(p58, 0, E1 / 3);
                Vector2 p60 = fun.Polar(p58, pi / 2, p);
                Vector2 p61 = fun.Polar(p60, 0, E1 / 3);


                //中间凹槽
                Vector2 p62 = fun.Polar(p33, 0, E / 2);
                Vector2 p63 = fun.Polar(p62, 0, b / 2);
                Vector2 p64 = fun.Polar(p62, pi, b / 2);
                Vector2 p65 = fun.Polar(p63, 135 * pi / 180, b / System.Math.Sqrt(2));



                Circle circle2 = new Circle(new Vector3(0, 0, 0), D1 / 2);//圆
                circle2.Lineweight = netDxf.Lineweight.W15;//W线宽;
                dxf.AddEntity(circle2);

                Vector2 p105 = fun.Polar(p0, pi, D1 / 2);
                Vector2 p205 = fun.Polar(p0, 0, D1 / 2);


                LwPolyline poly201 = new LwPolyline();
                poly201.Vertexes.Add(new LwPolylineVertex(p105));
                poly201.Vertexes[0].Bulge = Math.Tan(pi / 4);
                poly201.Vertexes.Add(new LwPolylineVertex(p205));
                poly201.Vertexes[1].Bulge = Math.Tan(pi / 4);
                poly201.Vertexes.Add(new LwPolylineVertex(p105));
                fun.PolyFill(dxf, poly201, 0.15, contour);


                /*
                //连线上卡槽
                Line line1 = new Line(p17, p20);
                Line line2 = new Line(p19, p21);
                line1.Lineweight = netDxf.Lineweight.W40;
                line2.Lineweight = netDxf.Lineweight.W40;
                fun.PolyFill(dxf, line1, 0.4, contour);
                */
                double hb = p17.X - p19.X;
                double xxb = d1 / 2;

                LwPolyline poly100 = new LwPolyline();
                poly100.Vertexes.Add(new LwPolylineVertex(p17));
                poly100.Vertexes.Add(new LwPolylineVertex(p20));
                poly100.Vertexes[1].Bulge = Math.Tan((10 * pi / 180) / 4);
                poly100.Vertexes.Add(new LwPolylineVertex(p21));
                poly100.Vertexes.Add(new LwPolylineVertex(p19));
                fun.PolyFill(dxf, poly100, 0.15, contour);



                Line line001 = new Line(p24, p23);
                Line line002 = new Line(p23, p25);
                line001.Lineweight = Lineweight.W25;
                line001.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line001);
                line002.Lineweight = Lineweight.W25;
                line002.Linetype = Linetype.Dashed;
                dxf.AddEntity(line002);

                Line line003 = new Line(p27, p26);
                Line line004 = new Line(p26, p28);
                line003.Lineweight = Lineweight.W25;
                line003.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line003);
                line004.Lineweight = Lineweight.W25;
                line004.Linetype = Linetype.Dashed;
                dxf.AddEntity(line004);








                /*
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
              
                
                poly1.Vertexes.Add(new LwPolylineVertex(p23));
                poly1.Vertexes.Add(new LwPolylineVertex(p25));
                poly1.Vertexes.Add(new LwPolylineVertex(p24));
                poly1.Vertexes[2].Bulge = Math.Tan(((fun.CalAngle(p0, p24) - fun.CalAngle(p0, p25))) / 4);
                fun.PolyFill(dxf, poly1, 0.3, contour);


                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p27));
                poly2.Vertexes.Add(new LwPolylineVertex(p26));
                poly2.Vertexes.Add(new LwPolylineVertex(p28));
                poly2.Vertexes.Add(new LwPolylineVertex(p27));
                poly2.Vertexes[2].Bulge = Math.Tan(((fun.CalAngle(p0, p27) - fun.CalAngle(p0, p28))) / 4);
                fun.PolyFill(dxf, poly2, 0.3, contour);
                */
                Line line005 = new Line(p29, p30);
                Line line006 = new Line(p30, p31);
                line005.Lineweight = Lineweight.W25;
                line005.Linetype = Linetype.Dashed;
                dxf.AddEntity(line005);
                line006.Lineweight = Lineweight.W25;
                line006.Linetype = Linetype.Dashed;
                dxf.AddEntity(line006);

                /*
                LwPolyline poly3 = new LwPolyline();
                poly3.Vertexes.Add(new LwPolylineVertex(p29));
                poly3.Vertexes.Add(new LwPolylineVertex(p30));
                poly3.Vertexes.Add(new LwPolylineVertex(p31));
                poly3.Vertexes[2].Bulge = Math.Tan(((fun.CalAngle(p0, p29) - fun.CalAngle(p0, p31))) / 4);
                fun.PolyFill(dxf, poly3, 0.3, contour);
                */






                //中心线
                Line line9 = new Line(p18, zxx1);
                Line line10 = new Line(zxx2, zxx3);
                line9.Lineweight = Lineweight.W15;//Lineweight指线宽
                line9.Layer = centre;//Layer指图层
                line9.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line9); //提取
                line10.Lineweight = Lineweight.W15;//Lineweight指线宽
                line10.Layer = centre;//Layer指图层
                line10.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
                dxf.AddEntity(line10); //提取

                //刨视图中心线
                Line line11 = new Line(pzxx, pzxx1);
                line11.Lineweight = Lineweight.W15;
                line11.Linetype = Linetype.DashDot;
                line11.Layer = centre;
                dxf.AddEntity(line11);




                //刨视图连线
                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p333));
                poly1.Vertexes.Add(new LwPolylineVertex(p34));
                poly1.Vertexes.Add(new LwPolylineVertex(p35));
                poly1.Vertexes.Add(new LwPolylineVertex(p36));
                poly1.Vertexes.Add(new LwPolylineVertex(p37));
                poly1.Vertexes.Add(new LwPolylineVertex(p38));
                poly1.Vertexes.Add(new LwPolylineVertex(p39));
                poly1.Vertexes.Add(new LwPolylineVertex(p42));
                poly1.Vertexes.Add(new LwPolylineVertex(p43));


                poly1.Vertexes[8].Bulge = Math.Tan((45 * pi / 180) / -4);

                poly1.Vertexes.Add(new LwPolylineVertex(p444));
                poly1.Vertexes.Add(new LwPolylineVertex(p44));
                poly1.Vertexes.Add(new LwPolylineVertex(p45));
                poly1.Vertexes.Add(new LwPolylineVertex(p334));

                poly1.Vertexes[12].Bulge = Math.Tan((45 * pi / 180) / -4);
                poly1.Vertexes.Add(new LwPolylineVertex(p46));
                poly1.Vertexes.Add(new LwPolylineVertex(p47));
                poly1.Vertexes[14].Bulge = Math.Tan((45 * pi / 180) / -4);
                poly1.Vertexes.Add(new LwPolylineVertex(p333));

                fun.PolyFill(dxf, poly1, 0.15, contour);

                //刨视图右边那个空框
                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p44));
                poly2.Vertexes.Add(new LwPolylineVertex(p48));
                poly2.Vertexes.Add(new LwPolylineVertex(p53));
                poly2.Vertexes.Add(new LwPolylineVertex(p45));
                poly2.Vertexes.Add(new LwPolylineVertex(p44));

                fun.PolyFill(dxf, poly2, 0.15, contour);


                //中间包括两杠的框
                LwPolyline poly3 = new LwPolyline();
                poly3.Vertexes.Add(new LwPolylineVertex(p34));
                poly3.Vertexes.Add(new LwPolylineVertex(p39));
                poly3.Vertexes.Add(new LwPolylineVertex(p48));
                poly3.Vertexes.Add(new LwPolylineVertex(p53));
                poly3.Vertexes.Add(new LwPolylineVertex(p34));

                fun.PolyFill(dxf, poly3, 0.15, contour);

                //中间的杠
                LwPolyline poly4 = new LwPolyline();
                poly4.Vertexes.Add(new LwPolylineVertex(p35));
                poly4.Vertexes.Add(new LwPolylineVertex(p36));
                poly4.Vertexes.Add(new LwPolylineVertex(p56));
                poly4.Vertexes.Add(new LwPolylineVertex(p54));
                poly4.Vertexes.Add(new LwPolylineVertex(p35));
                fun.PolyFill(dxf, poly4, 0.105, contour);

                LwPolyline poly5 = new LwPolyline();
                poly5.Vertexes.Add(new LwPolylineVertex(p56));
                poly5.Vertexes.Add(new LwPolylineVertex(p57));
                poly5.Vertexes.Add(new LwPolylineVertex(p55));
                poly5.Vertexes.Add(new LwPolylineVertex(p54));
                poly5.Vertexes.Add(new LwPolylineVertex(p56));
                fun.PolyFill(dxf, poly5, 0.105, contour);

                LwPolyline poly6 = new LwPolyline();
                poly6.Vertexes.Add(new LwPolylineVertex(p57));
                poly6.Vertexes.Add(new LwPolylineVertex(p51));
                poly6.Vertexes.Add(new LwPolylineVertex(p52));
                poly6.Vertexes.Add(new LwPolylineVertex(p55));
                poly6.Vertexes.Add(new LwPolylineVertex(p57));
                fun.PolyFill(dxf, poly6, 0.105, contour);


                LwPolyline poly7 = new LwPolyline();
                poly7.Vertexes.Add(new LwPolylineVertex(p37));
                poly7.Vertexes.Add(new LwPolylineVertex(p38));
                poly7.Vertexes.Add(new LwPolylineVertex(p60));
                poly7.Vertexes.Add(new LwPolylineVertex(p58));
                poly7.Vertexes.Add(new LwPolylineVertex(p37));
                fun.PolyFill(dxf, poly7, 0.105, contour);


                LwPolyline poly8 = new LwPolyline();
                poly8.Vertexes.Add(new LwPolylineVertex(p60));
                poly8.Vertexes.Add(new LwPolylineVertex(p61));
                poly8.Vertexes.Add(new LwPolylineVertex(p59));
                poly8.Vertexes.Add(new LwPolylineVertex(p58));
                poly8.Vertexes.Add(new LwPolylineVertex(p60));
                fun.PolyFill(dxf, poly8, 0.105, contour);

                LwPolyline poly9 = new LwPolyline();
                poly9.Vertexes.Add(new LwPolylineVertex(p61));
                poly9.Vertexes.Add(new LwPolylineVertex(p49));
                poly9.Vertexes.Add(new LwPolylineVertex(p50));
                poly9.Vertexes.Add(new LwPolylineVertex(p59));
                fun.PolyFill(dxf, poly9, 0.105, contour);



                LwPolyline poly10 = new LwPolyline();
                poly10.Vertexes.Add(new LwPolylineVertex(p63));
                poly10.Vertexes.Add(new LwPolylineVertex(p65));
                poly10.Vertexes.Add(new LwPolylineVertex(p64));
                fun.PolyFill(dxf, poly10, 0.105, contour);

                LwPolyline poly11 = new LwPolyline();
                poly11.Vertexes.Add(new LwPolylineVertex(p333));
                poly11.Vertexes.Add(new LwPolylineVertex(p34));
                poly11.Vertexes.Add(new LwPolylineVertex(p45));
                poly11.Vertexes.Add(new LwPolylineVertex(p334));
                poly11.Vertexes.Add(new LwPolylineVertex(p46));
                poly11.Vertexes.Add(new LwPolylineVertex(p64));
                poly11.Vertexes.Add(new LwPolylineVertex(p65));
                poly11.Vertexes.Add(new LwPolylineVertex(p63));
                poly11.Vertexes.Add(new LwPolylineVertex(p47));
                poly11.Vertexes.Add(new LwPolylineVertex(p333));

                //poly11.SetConstantWidth(0.05);
                poly11.IsClosed = true;
                fun.PolyFill(dxf, poly11, 0.105, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                String[] htype11 = new String[100];
                Line[] hline11 = new Line[100];
                Arc[] harc11 = new Arc[100];
                int hnumst11 = poly11.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst11; i++)
                {
                    htype11[i] = poly11.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype11[i] == "Line")
                    {
                        hline11[i] = (Line)poly11.Explode()[i];
                    }
                    if (htype11[i] == "Arc")
                    {
                        harc11[i] = (Arc)poly11.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype11, hnumst11, 45, 1, hline11, harc11, hatching);



                LwPolyline poly22 = new LwPolyline();
                poly22.Vertexes.Add(new LwPolylineVertex(p39));
                poly22.Vertexes.Add(new LwPolylineVertex(p42));
                poly22.Vertexes.Add(new LwPolylineVertex(p43));
                poly22.Vertexes.Add(new LwPolylineVertex(p444));
                poly22.Vertexes.Add(new LwPolylineVertex(p44));
                poly22.Vertexes.Add(new LwPolylineVertex(p39));


                //poly22.SetConstantWidth(0.05);
                poly22.IsClosed = true;
                fun.PolyFill(dxf, poly22, 0.105, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                String[] htype22 = new String[100];
                Line[] hline22 = new Line[100];
                Arc[] harc22 = new Arc[100];
                int hnumst22 = poly22.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst22; i++)
                {
                    htype22[i] = poly22.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype22[i] == "Line")
                    {
                        hline22[i] = (Line)poly22.Explode()[i];
                    }
                    if (htype22[i] == "Arc")
                    {
                        harc22[i] = (Arc)poly22.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype22, hnumst22, 45, 1, hline22, harc22, hatching);





                //排泄孔
                Arc arc1 = fun.DrawArc(p7, p1y, p5);

                fun.drawBArc(dxf, arc1, 0.15, contour);
                Arc arc2 = fun.DrawArc(p13, p3y, p9);
                fun.drawBArc(dxf, arc2, 0.15, contour);

                Arc arc3 = fun.DrawArc(p14, p2y, p10);
                fun.drawBArc(dxf, arc3, 0.15, contour);

                //螺纹孔
                Arc arc4 = fun.DrawArc(p6, p0, p16);
                fun.drawBArc(dxf, arc4, 0.15, contour);

                Arc arc5 = fun.DrawArc(p5, p0, p14);
                fun.drawBArc(dxf, arc5, 0.15, contour);

                Arc arc6 = fun.DrawArc(p10, p0, p13);
                fun.drawBArc(dxf, arc6, 0.15, contour);

                Arc arc7 = fun.DrawArc(p12, p0, p15);
                fun.drawBArc(dxf, arc7, 0.15, contour);

                Arc arc8 = fun.DrawArc(p9, p0, p7);
                fun.drawBArc(dxf, arc8, 0.15, contour);

                Arc arc9 = fun.DrawArc(p11, p0, p8);
                fun.drawBArc(dxf, arc9, 0.15, contour);

                Arc arc10 = fun.DrawArc(p19, p0, p17);
                fun.drawBArc(dxf, arc10, 0.15, contour);



                //标注
                Vector2 p0000 = fun.Polar(p0, pi / 2, D);
                Vector2 p1000 = fun.Polar(p0, 45 * pi / 180, D);
                Vector2 p1001 = fun.Polar(p0, 135 * pi / 180, D);
                Vector2 p1002 = fun.Polar(p1000, -45 * pi / 180, c);
                Vector2 p1003 = fun.Polar(p1001, -135 * pi / 180, c);



                //刨视图

                Line line1000 = new Line(p0, p1000);
                Line line1001 = new Line(p0, p1001);
                Line line1002 = new Line(p0, p0000);
                Line line1003 = new Line(p1001, p0);
                Line line1004 = new Line(p1002, p26);
                Line line1005 = new Line(p1003, p23);
                dxf.AddEntity(line1000);
                dxf.AddEntity(line1001);
                dxf.AddEntity(line1002);
                dxf.AddEntity(line1003);
                dxf.AddEntity(line1004);
                dxf.AddEntity(line1005);


                fun.jdbz2(dxf,  line1000, line1002, 15, 2.5, 2, 2.5, "45", "", "");
                fun.jdbz2(dxf, line1002, line1001,  15, 2.5, 2, 2.5, "45", "", "");
                fun.dimrot1(dxf, p1000, p1002, -45, 5, 5, 2.5, 2, 0.9, "c=" + c, "", "");
                fun.dimrot1(dxf, p1001, p1003, 45, 5, 5, 2.5, 2, 0.9, "c=" + c, "", "");

                fun.dimrot1(dxf, p42, p48, 0, D, 5, 2.5, 2, 0.9, "E1=" + E1, "", "");
                fun.dimrot1(dxf, p42, p44, 0, D + D / 2, 5, 2.5, 2, 0.9, "OAL=" + E, "", "");
                fun.dimrot1(dxf, p42, p33, -90, D + D / 2, 5, 2.5, 2, 0.9, "BD=" + D, "", "");
                fun.dimrot1(dxf, p48, p53, -90, D, 5, 2.5, 2, 0.9, "D1=" + D1, "", "");
                fun.dimrot1(dxf, p33, p47, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p33, fun.Polar(p33, 0, E / 2), 180, D + D / 2, 5, 2.5, 2, 0.9, "0.5E", "", "");
                fun.dimrot1(dxf, p46, p334, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p63, p64, 180, D / 2, 5, 2.5, 2, 0.9, "b" + b, "", "");








            }


            else
            {
                if (E1 == 0)
                {
                    E1 = E;
                }
                else if (E1 == 1)
                {
                    E1 = 8.0 / 9 * E;
                }



                Vector2 p0 = new Vector2(0, 0);
                Vector2 p1 = fun.Polar(p0, pi / 2, D1 / 2);
                Vector2 p1p = fun.Polar(p1, pi / -2, d1 / 2);
                Vector2 p2 = fun.Polar(p0, pi / 2 + 72 * pi / 180, D1 / 2);
                Vector2 p2p = fun.Polar(p2, -18 * pi / 180, d1 / 2);
                Vector2 p3 = fun.Polar(p0, 234 * pi / 180, D1 / 2);
                Vector2 p3p = fun.Polar(p3, 54 * pi / 180, d1 / 2);
                Vector2 p4 = fun.Polar(p0, 306 * pi / 180, D1 / 2);
                Vector2 p4p = fun.Polar(p4, 126 * pi / 180, d1 / 2);
                Vector2 p5 = fun.Polar(p0, 18 * pi / 180, D1 / 2);
                Vector2 p5p = fun.Polar(p5, -162 * pi / 180, d1 / 2);
                Vector2 p6 = fun.Polar(p0, pi * 0.5 + Math.Acos((yx * yx + zxj * zxj - jd1 * jd1) / (2 * yx * zxj)), yx);

                Vector2 p7 = fun.Polar(p0, pi / 2 + Math.Acos((yx2 * yx2 + zxj * zxj - jd1 * jd1) / (2 * yx2 * zxj)), yx2);
                Vector2 pz = fun.Polar(p0, pi / 2, D);
                Vector2 pz1 = fun.Polar(p0, pi / -2, D);
                Vector2 p8 = fun.mirrorpoint(p6, pz, pz1);
                Vector2 p9 = fun.mirrorpoint(p7, pz, pz1);

                //头顶卡槽
                Vector2 p26 = fun.Polar(p0, kc, D / 2);
                Vector2 p28 = fun.mirrorpoint(p26, pz, pz1);

                Vector2 p29 = fun.Polar(p26, kc - pi, D / 2 - D1 / 2);
                Vector2 p30 = fun.mirrorpoint(p29, pz, pz1);





                //正方形四点
                Vector2 p31 = fun.Polar(p0, 45 * pi / 180, D1 / 2);
                Vector2 p32 = fun.Polar(p0, 135 * pi / 180, D1 / 2);
                Vector2 p33 = fun.Polar(p0, -135 * pi / 180, D1 / 2);
                Vector2 p34 = fun.Polar(p0, -45 * pi / 180, D1 / 2);


                //中心线
                Vector2 pzx = fun.Polar(p0, 45 * pi / 180, D);
                Vector2 pzx1 = fun.Polar(p0, 135 * pi / 180, D);
                Vector2 pzx2 = fun.Polar(p0, -135 * pi / 180, D);
                Vector2 pzx3 = fun.Polar(p0, -45 * pi / 180, D);

                Vector2 pyz = fun.Polar(p0, 0, D);
                Vector2 pyz2 = fun.Polar(p0, pi, D);
                Vector2 pyz3 = fun.Polar(p0, pi / 2, D);
                Vector2 pyz4 = fun.Polar(p0, pi / -2, D);


                //四个槽孔


                Vector2 p35 = fun.Polar(p31, -45 * pi / 180, c);
                Vector2 p36 = fun.Polar(p0, 56 * pi / 180, D / 2);
                Vector2 p37 = fun.Polar(p0, 28 * pi / 180, D / 2);

                Vector2 p38 = fun.Polar(p32, -135 * pi / 180, c);
                Vector2 p39 = fun.Polar(p0, 124 * pi / 180, D / 2);
                Vector2 p40 = fun.Polar(p0, 152 * pi / 180, D / 2);

                Vector2 p41 = fun.Polar(p0, -121 * pi / 180, D / 2);
                Vector2 p42 = fun.Polar(p0, -149 * pi / 180, D / 2);

                Vector2 p43 = fun.Polar(p34, 0, ((D / 2 - D1 / 2) / (Math.Cos(45 * pi / 180))));
                Vector2 p44 = fun.Polar(p34, -90 * pi / 180, ((D / 2 - D1 / 2) / (Math.Cos(45 * pi / 180))));

                Vector2 p45 = fun.Polar(p26, kc - pi, D / 2 - DD1 / 2);
                Vector2 p46 = fun.mirrorpoint(p45, pz, pz1);


                //刨切线
                Vector2 p91 = fun.Polar(p0, pi / 2 + (ajj * pi / 180), D + 5);
                Vector2 p92 = fun.Polar(p91, (pi / 2 + (ajj * pi / 180)) - (90 * pi / 180), 5);
                Vector2 p93 = fun.Polar(p0, pi / -4, D + 5);
                Vector2 p94 = fun.Polar(p93, pi / 4, 5);
                Vector2 p95 = fun.Polar(p92, (pi / 2 + (ajj * pi / 180)), 0.71 / 2);
                Vector2 p96 = fun.Polar(p92, (pi / 2 + (ajj * pi / 180)) - pi, 0.71 / 2);
                Vector2 p97 = fun.Polar(p92, (pi / 2 + (ajj * pi / 180)) - (90 * pi / 180), 2.0);
                Vector2 p98 = fun.Polar(p94, pi / 2 + pi / 4, 0.71 / 2);
                Vector2 p99 = fun.Polar(p94, pi / -4, 0.71 / 2);
                Vector2 p105 = fun.Polar(p94, pi / 4, 2.0);
                Vector2 p108 = fun.Polar(p92, pi, 2);
                Vector2 p107 = fun.Polar(p94, pi / -4, 2);





                Line line105 = new Line(p0, p91);
                line105.Lineweight = Lineweight.W25;
                line105.Linetype = Linetype.DashDot;
                dxf.AddEntity(line105);
                Line line106 = new Line(p91, p92);
                line106.Lineweight = Lineweight.W25;

                dxf.AddEntity(line106);
                Line line107 = new Line(p0, p93);
                line107.Lineweight = Lineweight.W25;
                line107.Linetype = Linetype.DashDot;
                dxf.AddEntity(line107);
                Line line108 = new Line(p93, p94);
                line108.Lineweight = Lineweight.W25;

                dxf.AddEntity(line108);
                Solid entity = new Solid(p95, p96, p97);
                dxf.AddEntity(entity);

                Solid entity1 = new Solid(p98, p99, p105);
                dxf.AddEntity(entity1);

                Text txt = new Text("A", p108, 2.5, 2);
                Text txt1 = new Text("A", p107, 2.5, 2);
                dxf.AddEntity(txt);
                dxf.AddEntity(txt1);

                var p10 = fun.PointRotate(p0, p6, 72 * pi / 180);
                var p11 = fun.PointRotate(p0, p6, 144 * pi / 180);
                var p12 = fun.PointRotate(p0, p6, 216 * pi / 180);
                var p13 = fun.PointRotate(p0, p6, 288 * pi / 180);
                var p14 = fun.PointRotate(p0, p7, 72 * pi / 180);
                var p15 = fun.PointRotate(p0, p7, 144 * pi / 180);
                var p16 = fun.PointRotate(p0, p7, 216 * pi / 180);
                var p17 = fun.PointRotate(p0, p7, 288 * pi / 180);
                var p18 = fun.PointRotate(p0, p8, 72 * pi / 180);
                var p19 = fun.PointRotate(p0, p8, 144 * pi / 180);
                var p20 = fun.PointRotate(p0, p8, 216 * pi / 180);
                var p21 = fun.PointRotate(p0, p8, 288 * pi / 180);
                var p22 = fun.PointRotate(p0, p9, 72 * pi / 180);
                var p23 = fun.PointRotate(p0, p9, 144 * pi / 180);
                var p24 = fun.PointRotate(p0, p9, 216 * pi / 180);
                var p25 = fun.PointRotate(p0, p9, 288 * pi / 180);

                /*
                //头顶卡槽连线
                Line line1 = new Line(p26,p29);
                line1.Lineweight = Lineweight.W50;
                line1.Layer = contour ;
                dxf.AddEntity(line1);
                



                Line line2 = new Line(p28, p30);
                line2.Lineweight = Lineweight.W50;
                line2.Layer = contour;
                dxf.AddEntity(line2);
                */

                double hb1 = p26.X - p28.X;
                double xxb1 = d1 / 2;

                LwPolyline poly100 = new LwPolyline();
                poly100.Vertexes.Add(new LwPolylineVertex(p26));
                poly100.Vertexes.Add(new LwPolylineVertex(p29));
                poly100.Vertexes[1].Bulge = Math.Tan((10 * pi / 180) / 4);
                poly100.Vertexes.Add(new LwPolylineVertex(p30));
                poly100.Vertexes.Add(new LwPolylineVertex(p28));
                fun.PolyFill(dxf, poly100, 0.4, contour);




                //最小圆的正方形虚线
                Line line3 = new Line(p31, p32);
                line3.Linetype = Linetype.Dashed;
                line3.Layer = refin;
                line3.Lineweight = Lineweight.W25;
                dxf.AddEntity(line3);
                Line line4 = new Line(p32, p33);
                line4.Linetype = Linetype.Dashed;
                line4.Layer = refin;
                line4.Lineweight = Lineweight.W25;
                dxf.AddEntity(line4);

                Line line5 = new Line(p33, p34);
                line5.Linetype = Linetype.Dashed;
                line5.Layer = refin;
                line5.Lineweight = Lineweight.W25;
                dxf.AddEntity(line5);
                Line line6 = new Line(p34, p31);
                line6.Linetype = Linetype.Dashed;
                line6.Layer = refin;
                line6.Lineweight = Lineweight.W25;
                dxf.AddEntity(line6);
                //四个槽孔
                Line line7 = new Line(p35, p36);
                line7.Linetype = Linetype.Dashed;
                line7.Layer = refin;
                line7.Lineweight = Lineweight.W35;
                dxf.AddEntity(line7);

                Line line8 = new Line(p35, p37);
                line8.Linetype = Linetype.Dashed;
                line8.Layer = refin;
                line8.Lineweight = Lineweight.W35;
                dxf.AddEntity(line8);
                Line line9 = new Line(p38, p39);
                line9.Linetype = Linetype.Dashed;
                line9.Layer = refin;
                line9.Lineweight = Lineweight.W35;
                dxf.AddEntity(line9);
                Line line10 = new Line(p38, p40);
                line10.Linetype = Linetype.Dashed;
                line10.Layer = refin;
                line10.Lineweight = Lineweight.W35;
                dxf.AddEntity(line10);
                Line line11 = new Line(p33, p41);
                line11.Linetype = Linetype.Dashed;
                line11.Layer = refin;
                line11.Lineweight = Lineweight.W35;
                dxf.AddEntity(line11);
                Line line12 = new Line(p33, p42);
                line12.Linetype = Linetype.Dashed;
                line12.Layer = refin;
                line12.Lineweight = Lineweight.W35;
                dxf.AddEntity(line12);
                Line line13 = new Line(p34, p43);
                line13.Linetype = Linetype.Dashed;
                line13.Layer = refin;
                line13.Lineweight = Lineweight.W35;
                dxf.AddEntity(line13);
                Line line14 = new Line(p34, p44);
                line14.Linetype = Linetype.Dashed;
                line14.Layer = refin;
                line14.Lineweight = Lineweight.W35;
                dxf.AddEntity(line14);

                //中心线
                Line line15 = new Line(pzx, pzx2);
                line15.Linetype = Linetype.DashDot;
                line15.Layer = centre;
                line15.Lineweight = Lineweight.W25;
                dxf.AddEntity(line15);

                Line line16 = new Line(pzx1, pzx3);
                line16.Linetype = Linetype.DashDot;
                line16.Layer = centre;
                line16.Lineweight = Lineweight.W25;
                dxf.AddEntity(line16);

                Line line17 = new Line(pyz, pyz2);
                line17.Linetype = Linetype.DashDot;
                line17.Layer = centre;
                line17.Lineweight = Lineweight.W25;
                dxf.AddEntity(line17);

                Line line18 = new Line(pyz3, pyz4);
                line18.Linetype = Linetype.DashDot;
                line18.Layer = centre;
                line18.Lineweight = Lineweight.W25;
                dxf.AddEntity(line18);





                //外轮廓弧
                Arc arc1 = fun.DrawArc(p8, p1p, p6);
                fun.drawBArc(dxf, arc1, 0.5, contour);
                Arc arc2 = fun.DrawArc(p18, p5p, p10);
                fun.drawBArc(dxf, arc2, 0.5, contour);
                Arc arc3 = fun.DrawArc(p19, p4p, p11);
                fun.drawBArc(dxf, arc3, 0.5, contour);
                Arc arc4 = fun.DrawArc(p20, p3p, p12);
                fun.drawBArc(dxf, arc4, 0.5, contour);
                Arc arc5 = fun.DrawArc(p21, p2p, p13);
                fun.drawBArc(dxf, arc5, 0.5, contour);

                /*
                  LwPolyline poly1 = new LwPolyline();
                  poly1.Vertexes.Add(new LwPolylineVertex(p));
                  poly1.Vertexes[2].Bulge = -Math.Tan((pi - epsr) / 4); 
                   poly1.Vertexes.Add(new LwPolylineVertex(p29));
                  fun.PolyFill(dxf, poly1, 0.4, contour);
                
                
                double gd = p1p.Y - p6.Y;
                double db = p8.X;
                double xb= System.Math.Sqrt(Math .Pow (gd,2)+Math.Pow (db,2));
                double jd = Math .Acos ((gd*gd+xb*xb-db*db)/(2*gd*xb));

                double xb1 = Math.Sqrt(Math.Pow(p8.X, 2) + Math.Pow(p8.Y, 2));
                double xb2= Math.Sqrt(Math.Pow(p10.X, 2) + Math.Pow(p10.Y, 2));
                double xb3= Math.Sqrt(Math.Pow(p10.X-p8.X , 2) + Math.Pow(p8.Y-p10.Y , 2));
                double jd2 = Math.Acos((xb1 * xb1 + xb2 * xb2 - xb3 * xb3) / (2 * xb1 * xb2));
                LwPolyline poly100 = new LwPolyline();
                poly100.Vertexes.Add(new LwPolylineVertex(p6));
                poly100.Vertexes[0].Bulge = Math.Tan((pi*2-jd*2) / -4);
                poly100.Vertexes.Add(new LwPolylineVertex(p8));
                poly100.Vertexes[1].Bulge = Math.Tan((jd2)/-4);
                poly100.Vertexes.Add(new LwPolylineVertex(p10));
                poly100.Vertexes.Add(new LwPolylineVertex(p18));
                poly100.Vertexes.Add(new LwPolylineVertex(p11));
                poly100.Vertexes.Add(new LwPolylineVertex(p19));
                poly100.Vertexes.Add(new LwPolylineVertex(p12));
                poly100.Vertexes.Add(new LwPolylineVertex(p20));
                poly100.Vertexes.Add(new LwPolylineVertex(p13));
                poly100.Vertexes.Add(new LwPolylineVertex(p21));
                poly100.Vertexes.Add(new LwPolylineVertex(p6));
                */

                //fun.PolyFill(dxf, poly100, 0.4, contour);
                //螺纹弧

                Arc arc6 = fun.DrawArc(p6, p0, p21);
                fun.drawBArc(dxf, arc6, 0.5, contour);
                Arc arc7 = fun.DrawArc(p13, p0, p20);
                fun.drawBArc(dxf, arc7, 0.5, contour);
                Arc arc8 = fun.DrawArc(p12, p0, p19);
                fun.drawBArc(dxf, arc8, 0.5, contour);
                Arc arc9 = fun.DrawArc(p11, p0, p18);
                fun.drawBArc(dxf, arc9, 0.5, contour);
                Arc arc10 = fun.DrawArc(p10, p0, p8);
                fun.drawBArc(dxf, arc10, 0.5, contour);

                Arc arc11 = fun.DrawArc(p7, p0, p25);
                fun.drawBArc(dxf, arc11, 0.5, contour);
                Arc arc12 = fun.DrawArc(p17, p0, p24);
                fun.drawBArc(dxf, arc12, 0.5, contour);
                Arc arc13 = fun.DrawArc(p16, p0, p23);
                fun.drawBArc(dxf, arc13, 0.5, contour);
                Arc arc14 = fun.DrawArc(p15, p0, p22);
                fun.drawBArc(dxf, arc14, 0.5, contour);
                Arc arc15 = fun.DrawArc(p14, p0, p9);
                fun.drawBArc(dxf, arc15, 0.5, contour);
                //最大两个弧度
                Arc arc16 = fun.DrawArc(p28, p0, p26);
                fun.drawBArc(dxf, arc16, 0.5, contour);
                Arc arc17 = fun.DrawArc(p46, p0, p45);
                fun.drawBArc(dxf, arc17, 0.5, contour);
                Circle circle1 = new Circle(new Vector3(0, 0, 0), D1 / 2);//圆
                circle1.Linetype = Linetype.Dashed;
                circle1.Lineweight = netDxf.Lineweight.W50;
                circle1.Layer = contour;
                dxf.AddEntity(circle1);


                Vector2 p106 = fun.Polar(p0, pi, D1 / 2);
                Vector2 p206 = fun.Polar(p0, 0, D1 / 2);


                LwPolyline poly200 = new LwPolyline();
                poly200.Vertexes.Add(new LwPolylineVertex(p106));
                poly200.Vertexes[0].Bulge = Math.Tan(pi / 4);
                poly200.Vertexes.Add(new LwPolylineVertex(p206));
                poly200.Vertexes[1].Bulge = Math.Tan(pi / 4);
                poly200.Vertexes.Add(new LwPolylineVertex(p106));
                fun.PolyFill(dxf, poly200, 0.5, contour);

                //刨视图


                Vector2 p47 = fun.Polar(p0, pi / -2, D / 2);
                Vector2 p48 = fun.Polar(p47, 0, D + d);
                Vector2 pzstd = fun.Polar(p0, pi / -2, D1 / 2);
                //跟进一条
                Vector2 pgj = fun.Polar(p48, pi / 2, a);
                Vector2 p49 = fun.Polar(pzstd, 0, D + d);

                //镜像用的中分线
                Vector2 pjx = fun.Polar(p48, 0, E1 / 2);
                Vector2 pjx1 = fun.Polar(pjx, pi / 2, D + D);
                Vector2 pjx2 = fun.Polar(pjx, pi / -2, D);


                Vector2 p50;
                Vector2 p51;
                Vector2 p52;
                Vector2 p53;
                Vector2 p54;
                Vector2 p55;
                Vector2 p56;
                Vector2 p68;
                Vector2 p69;
                Vector2 p70;
                Vector2 p71;
                Vector2 p72;
                Vector2 p73;
                Vector2 p76;
                Vector2 p77;
                Vector2 p78;
                Vector2 p79;
                Vector2 p80;
                Vector2 p81;
                Vector2 p82;
                Vector2 p83;
                Vector2 p84;
                Vector2 p85;
                Vector2 p86;
                Vector2 p87;
                if (ajj > 45)
                {
                    p50 = fun.Polar(p49, pi / 2, D1 / 4);
                    p51 = fun.Polar(p50, pi / 2, p);
                    p52 = fun.Polar(p48, pi / 2, D / 2);//中心点
                    p53 = fun.Polar(p52, pi / 2, (D1 / 2.0) * (1.0 / 3));
                    p54 = fun.Polar(p53, pi / 2, p);
                    p55 = fun.Polar(p52, pi / 2, (D1 / 2) * (2.0 / 3));
                    p56 = fun.Polar(p55, pi / 2, p);

                    //中间的镜像点
                    p68 = fun.mirrorpoint(p50, pjx1, pjx2);
                    p69 = fun.mirrorpoint(p51, pjx1, pjx2);
                    p70 = fun.mirrorpoint(p53, pjx1, pjx2);
                    p71 = fun.mirrorpoint(p54, pjx1, pjx2);
                    p72 = fun.mirrorpoint(p55, pjx1, pjx2);
                    p73 = fun.mirrorpoint(p56, pjx1, pjx2);

                    //中间的点
                    p76 = fun.Polar(p50, pi / 4, System.Math.Sqrt(2) * (E1 / 3));
                    p77 = fun.Polar(p76, 0, E1 * l);
                    p78 = fun.Polar(p76, pi / 2, p);
                    p79 = fun.Polar(p77, pi / 2, p);
                    p80 = fun.Polar(p53, -45 * pi / 180, System.Math.Sqrt(2) * (E1 / 3));
                    p81 = fun.Polar(p80, 0, E1 * l);
                    p82 = fun.Polar(p80, pi / 2, p);
                    p83 = fun.Polar(p81, pi / 2, p);

                    p84 = fun.Polar(p55, -45 * pi / 180, System.Math.Sqrt(2) * (E1 / 3));
                    p85 = fun.Polar(p84, 0, E1 * l);
                    p86 = fun.Polar(p84, pi / 2, p);
                    p87 = fun.Polar(p85, pi / 2, p);

                    LwPolyline poly11 = new LwPolyline();
                    poly11.Vertexes.Add(new LwPolylineVertex(p56));
                    poly11.Vertexes.Add(new LwPolylineVertex(p86));
                    poly11.Vertexes.Add(new LwPolylineVertex(p84));
                    poly11.Vertexes.Add(new LwPolylineVertex(p55));
                    poly11.Vertexes.Add(new LwPolylineVertex(p56));
                    fun.PolyFill(dxf, poly11, 0.35, contour);

                    LwPolyline poly12 = new LwPolyline();
                    poly12.Vertexes.Add(new LwPolylineVertex(p86));
                    poly12.Vertexes.Add(new LwPolylineVertex(p87));
                    poly12.Vertexes.Add(new LwPolylineVertex(p85));
                    poly12.Vertexes.Add(new LwPolylineVertex(p84));
                    poly12.Vertexes.Add(new LwPolylineVertex(p86));
                    fun.PolyFill(dxf, poly12, 0.35, contour);

                    LwPolyline poly13 = new LwPolyline();
                    poly13.Vertexes.Add(new LwPolylineVertex(p87));
                    poly13.Vertexes.Add(new LwPolylineVertex(p73));
                    poly13.Vertexes.Add(new LwPolylineVertex(p72));
                    poly13.Vertexes.Add(new LwPolylineVertex(p85));
                    poly13.Vertexes.Add(new LwPolylineVertex(p87));
                    fun.PolyFill(dxf, poly13, 0.35, contour);

                }
                else
                {

                    if (drjj == 1 && l == 1)
                    {
                        drjj = 0 * pi / 180;
                        l = (1.0 / 3) * E1;

                    }
                    else if (drjj == 1 && l == 3)
                    {
                        drjj = 45.0 / 4 * pi / 180;
                        l = (9.0 / 10 * E1) / (Math.Cos(drjj));


                    }
                    else if (drjj == 1 && l == 2)
                    {
                        drjj = 0 * pi / 180;
                        l = (4.0 / 5) * E1;
                    }


                    p50 = fun.Polar(p49, pi / 2, D1 / 4);
                    p51 = fun.Polar(p50, pi / 2, p);
                    p52 = fun.Polar(p48, pi / 2, D / 2);//中心点
                    p53 = fun.Polar(p52, pi / 2, (D1 / 2.0) * (1.0 / 3));
                    p54 = fun.Polar(p53, pi / 2, p);
                    //中间的镜像点
                    p68 = fun.mirrorpoint(p50, pjx1, pjx2);
                    p69 = fun.mirrorpoint(p51, pjx1, pjx2);
                    p70 = fun.mirrorpoint(p53, pjx1, pjx2);
                    p71 = fun.mirrorpoint(p54, pjx1, pjx2);
                    //中间的点

                    p76 = fun.Polar(p50, 45 * pi / 180, System.Math.Sqrt(2) * (E1 / 10));
                    p77 = fun.Polar(p76, (0 * pi / 180 + drjj), (l));
                    p78 = fun.Polar(p76, pi / 2, p);
                    p79 = fun.Polar(p77, pi / 2, p);
                    p80 = fun.Polar(p53, -45 * pi / 180, System.Math.Sqrt(2) * (E1 / 10));
                    p81 = fun.Polar(p80, (0 * pi / 180 - drjj), (l));
                    p82 = fun.Polar(p80, pi / 2, p);
                    p83 = fun.Polar(p81, pi / 2, p);

                }


                Vector2 p57 = fun.Polar(p52, pi / 2, D1 / 2);
                Vector2 p58 = fun.Polar(p52, pi / 2, D / 2);
                Vector2 pdy = fun.Polar(p58, 0, E - a);
                Vector2 pdy1 = new Vector2(p58.X + E, p58.Y - a);
                Vector2 p59 = fun.Polar(p58, 0, E);
                Vector2 p60 = new Vector2(p59.X, p52.Y + DD1 / 2);
                Vector2 p61 = fun.Polar(p60, pi / -2, DD1);
                //临时加的
                Vector2 pdj = new Vector2(p48.X + E, p48.Y + a);
                Vector2 p62 = new Vector2(p61.X - a, p48.Y);
                Vector2 p63 = fun.Polar(p48, 0, (E / 2) + (b / 2));
                Vector2 p64 = fun.Polar(p63, pi, b);
                Vector2 p65 = fun.Polar(p48, 0, a);

                //刨切线
                Vector2 p109 = fun.Polar(p58, pi / 2, 2);
                Text txt2 = new Text("A-A", p109, 2.5, 2);
                dxf.AddEntity(txt2);


                //右边的框
                Vector2 p66 = fun.Polar(p60, pi, E - E1);
                Vector2 p67 = fun.Polar(p66, pi / -2, DD1);
                Vector2 pjxx = fun.Polar(p48, 0, E1 / 2);
                Vector2 pjxx1 = fun.Polar(pjxx, pi / 2, D);
                Vector2 p100 = fun.mirrorpoint(p57, pjxx, pjxx1);
                Vector2 p110 = fun.mirrorpoint(p49, pjxx, pjxx1);












                //下面的三角形顶点
                Vector2 p88 = fun.Polar(p63, 135 * pi / 180, b * (1 / System.Math.Sqrt(2)));

                if (sh == 0)
                {
                    LwPolyline poly20 = new LwPolyline();
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    poly20.Vertexes.Add(new LwPolylineVertex(p88));
                    poly20.Vertexes.Add(new LwPolylineVertex(p64));
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    fun.PolyFill(dxf, poly20, 0.5, contour);

                }
                else
                {
                    LwPolyline poly20 = new LwPolyline();
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    poly20.Vertexes.Add(new LwPolylineVertex(p88));
                    poly20.Vertexes.Add(new LwPolylineVertex(p64));
                    poly20.Vertexes[2].Bulge = Math.Tan((90 * pi / 180) / -4);
                    poly20.Vertexes.Add(new LwPolylineVertex(p63));
                    fun.PolyFill(dxf, poly20, 0.5, contour);
                }




                //中心线
                Vector2 p89 = fun.Polar(p52, pi, b);
                Vector2 p90 = fun.Polar(p89, 0, E + 2 * b);
                Line line100 = new Line(p89, p90);
                line100.Linetype = Linetype.DashDot;
                line100.Layer = centre;
                line100.Lineweight = Lineweight.W25;
                dxf.AddEntity(line100);



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(p49));
                poly1.Vertexes.Add(new LwPolylineVertex(p57));
                poly1.Vertexes.Add(new LwPolylineVertex(p100));
                poly1.Vertexes.Add(new LwPolylineVertex(p110));
                poly1.Vertexes.Add(new LwPolylineVertex(p49));
                fun.PolyFill(dxf, poly1, 0.5, contour);



                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(p60));
                poly2.Vertexes.Add(new LwPolylineVertex(p66));
                poly2.Vertexes.Add(new LwPolylineVertex(p67));
                poly2.Vertexes.Add(new LwPolylineVertex(p61));
                poly2.Vertexes.Add(new LwPolylineVertex(p60));
                fun.PolyFill(dxf, poly2, 0.5, contour);



                //倒圆角
                if (dj == 1)
                {
                    LwPolyline poly3 = new LwPolyline();
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    poly3.Vertexes.Add(new LwPolylineVertex(p58));
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy));
                    poly3.Vertexes[2].Bulge = Math.Tan((45 * pi / 180) / -4);
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy1));
                    poly3.Vertexes.Add(new LwPolylineVertex(p60));
                    poly3.Vertexes.Add(new LwPolylineVertex(p66));
                    poly3.Vertexes.Add(new LwPolylineVertex(p100));
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    //poly3.SetConstantWidth(0.05);
                    poly3.IsClosed = true;
                    fun.PolyFill(dxf, poly3, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    Arc[] harc3 = new Arc[100];
                    int hnumst3 = poly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = poly3.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)poly3.Explode()[i];
                        }
                        if (htype3[i] == "Arc")
                        {
                            harc3[i] = (Arc)poly3.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype3, hnumst3, 45, 1, hline3, harc3, hatching);


                    LwPolyline poly4 = new LwPolyline();
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));
                    poly4.Vertexes.Add(new LwPolylineVertex(p49));
                    poly4.Vertexes.Add(new LwPolylineVertex(p110));
                    poly4.Vertexes.Add(new LwPolylineVertex(p67));
                    poly4.Vertexes.Add(new LwPolylineVertex(p61));
                    poly4.Vertexes.Add(new LwPolylineVertex(pdj));

                    poly4.Vertexes[5].Bulge = Math.Tan((45 * pi / 180) / -4);

                    poly4.Vertexes.Add(new LwPolylineVertex(p62));
                    poly4.Vertexes.Add(new LwPolylineVertex(p63));
                    poly4.Vertexes.Add(new LwPolylineVertex(p88));
                    poly4.Vertexes.Add(new LwPolylineVertex(p64));
                    poly4.Vertexes.Add(new LwPolylineVertex(p65));
                    poly4.Vertexes[10].Bulge = Math.Tan((45 * pi / 180) / -4);
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));

                    //poly4.SetConstantWidth(0.05);
                    poly4.IsClosed = true;
                    fun.PolyFill(dxf, poly4, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype4 = new String[100];
                    Line[] hline4 = new Line[100];
                    Arc[] harc4 = new Arc[100];
                    int hnumst4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst4; i++)
                    {
                        htype4[i] = poly4.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype4[i] == "Line")
                        {
                            hline4[i] = (Line)poly4.Explode()[i];
                        }
                        if (htype4[i] == "Arc")
                        {
                            harc4[i] = (Arc)poly4.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype4, hnumst4, 45, 1, hline4, harc4, hatching);
                }


                //倒斜角
                else
                {

                    LwPolyline poly3 = new LwPolyline();
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    Vector2 p1000 = fun.Polar(p58, pi / -2, a);
                    poly3.Vertexes.Add(new LwPolylineVertex(p1000));
                    Vector2 p1001 = fun.Polar(p58, 0, a);
                    poly3.Vertexes.Add(new LwPolylineVertex(p1001));
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy));
                    poly3.Vertexes.Add(new LwPolylineVertex(pdy1));
                    poly3.Vertexes.Add(new LwPolylineVertex(p60));
                    poly3.Vertexes.Add(new LwPolylineVertex(p66));
                    poly3.Vertexes.Add(new LwPolylineVertex(p100));
                    poly3.Vertexes.Add(new LwPolylineVertex(p57));
                    //poly3.SetConstantWidth(0.05);
                    poly3.IsClosed = true;
                    fun.PolyFill(dxf, poly3, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    Arc[] harc3 = new Arc[100];
                    int hnumst3 = poly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = poly3.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)poly3.Explode()[i];
                        }
                        if (htype3[i] == "Arc")
                        {
                            harc3[i] = (Arc)poly3.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype3, hnumst3, 45, 1, hline3, harc3, hatching);


                    LwPolyline poly4 = new LwPolyline();
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));
                    poly4.Vertexes.Add(new LwPolylineVertex(p49));
                    poly4.Vertexes.Add(new LwPolylineVertex(p110));
                    poly4.Vertexes.Add(new LwPolylineVertex(p67));
                    poly4.Vertexes.Add(new LwPolylineVertex(p61));
                    poly4.Vertexes.Add(new LwPolylineVertex(pdj));
                    poly4.Vertexes.Add(new LwPolylineVertex(p62));
                    poly4.Vertexes.Add(new LwPolylineVertex(p63));
                    poly4.Vertexes.Add(new LwPolylineVertex(p88));
                    poly4.Vertexes.Add(new LwPolylineVertex(p64));
                    poly4.Vertexes.Add(new LwPolylineVertex(p65));
                    poly4.Vertexes.Add(new LwPolylineVertex(pgj));
                    //poly4.SetConstantWidth(0.05);
                    poly4.IsClosed = true;
                    fun.PolyFill(dxf, poly4, 0.5, contour);//将poly1这条线设置为宽度0.4的实体，contour实体。
                    String[] htype4 = new String[100];
                    Line[] hline4 = new Line[100];
                    Arc[] harc4 = new Arc[100];
                    int hnumst4 = poly4.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst4; i++)
                    {
                        htype4[i] = poly4.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                        if (htype4[i] == "Line")
                        {
                            hline4[i] = (Line)poly4.Explode()[i];
                        }
                        if (htype4[i] == "Arc")
                        {
                            harc4[i] = (Arc)poly4.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype4, hnumst4, 45, 1, hline4, harc4, hatching);
                }
                LwPolyline poly5 = new LwPolyline();
                poly5.Vertexes.Add(new LwPolylineVertex(p50));
                poly5.Vertexes.Add(new LwPolylineVertex(p51));
                poly5.Vertexes.Add(new LwPolylineVertex(p78));
                poly5.Vertexes.Add(new LwPolylineVertex(p76));
                poly5.Vertexes.Add(new LwPolylineVertex(p50));
                fun.PolyFill(dxf, poly5, 0.35, contour);

                LwPolyline poly6 = new LwPolyline();
                poly6.Vertexes.Add(new LwPolylineVertex(p78));
                poly6.Vertexes.Add(new LwPolylineVertex(p79));
                poly6.Vertexes.Add(new LwPolylineVertex(p77));
                poly6.Vertexes.Add(new LwPolylineVertex(p76));
                poly6.Vertexes.Add(new LwPolylineVertex(p78));
                fun.PolyFill(dxf, poly6, 0.35, contour);

                LwPolyline poly7 = new LwPolyline();
                poly7.Vertexes.Add(new LwPolylineVertex(p79));
                poly7.Vertexes.Add(new LwPolylineVertex(p69));
                poly7.Vertexes.Add(new LwPolylineVertex(p68));
                poly7.Vertexes.Add(new LwPolylineVertex(p77));
                poly7.Vertexes.Add(new LwPolylineVertex(p79));
                fun.PolyFill(dxf, poly7, 0.35, contour);

                LwPolyline poly8 = new LwPolyline();
                poly8.Vertexes.Add(new LwPolylineVertex(p53));
                poly8.Vertexes.Add(new LwPolylineVertex(p54));
                poly8.Vertexes.Add(new LwPolylineVertex(p82));
                poly8.Vertexes.Add(new LwPolylineVertex(p80));
                poly8.Vertexes.Add(new LwPolylineVertex(p53));
                fun.PolyFill(dxf, poly8, 0.35, contour);

                LwPolyline poly9 = new LwPolyline();
                poly9.Vertexes.Add(new LwPolylineVertex(p82));
                poly9.Vertexes.Add(new LwPolylineVertex(p83));
                poly9.Vertexes.Add(new LwPolylineVertex(p81));
                poly9.Vertexes.Add(new LwPolylineVertex(p80));
                poly9.Vertexes.Add(new LwPolylineVertex(p82));
                fun.PolyFill(dxf, poly9, 0.35, contour);

                LwPolyline poly10 = new LwPolyline();
                poly10.Vertexes.Add(new LwPolylineVertex(p83));
                poly10.Vertexes.Add(new LwPolylineVertex(p71));
                poly10.Vertexes.Add(new LwPolylineVertex(p70));
                poly10.Vertexes.Add(new LwPolylineVertex(p81));
                poly10.Vertexes.Add(new LwPolylineVertex(p83));
                fun.PolyFill(dxf, poly10, 0.35, contour);




                //标注
                Vector2 p1004 = fun.Polar(p0, pi / 2, D / 2);
                Vector2 p1005 = fun.Polar(p48, 0, E / 2);
                fun.jdbz2(dxf, new Line(p0, p31), new Line(p0, p1004), D - 1, 2.5, 2, 2.5, "45", "", "");
                fun.jdbz2(dxf,  new Line(p0, p1004), new Line(p0, p32), D - 1, 2.5, 2, 2.5, "45", "", "");
                fun.jdbz2(dxf, new Line(p34, p44), new Line(p34, p43), (D - D1 / 2 - 1), 2.5, 2, 2.5, "90", "", "");
                fun.dimrot1(dxf, p0, p35, -45, D / 2, 5, 2.5, 2, 0.9, "c=" + c, "", "");
                fun.dimrot1(dxf, p0, p38, 45, D / 2, 5, 2.5, 2, 0.9, "c=" + c, "", "");


                fun.dimrot1(dxf, p58, p66, 0, D / 2, 5, 2.5, 2, 0.9, "E1=" + E1, "", "");
                fun.dimrot1(dxf, p58, p60, 0, D, 5, 2.5, 2, 0.9, "OAL=" + E, "", "");
                fun.dimrot1(dxf, p58, p48, -90, D, 5, 2.5, 2, 0.9, "BD=" + D, "", "");
                //fun.dimrot1(dxf, p66, p67, -90, D/2, 5, 2.5, 2, 0.9, "D1", "", "");
                fun.dimrot1(dxf, p48, p65, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p62, p61, 180, D, 5, 2.5, 2, 0.9, "a=" + a, "", "");
                fun.dimrot1(dxf, p48, p1005, 180, D * 2, 5, 2.5, 2, 0.9, "0.5E", "", "");
                fun.dimrot1(dxf, fun.Polar(p48, 0, E / 2), fun.Polar(p48, pi, E / 2), 180, D / 2, 5, 2.5, 2, 0.9, "b=" + b, "", "");


            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
